package com.zcoj.wx.pojo;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;

/**
 * @author chenbin
 * @version 1.0
 * @description: TODO
 * @date 2023/8/19 10:54
 */
@Data
@NoArgsConstructor
@TableName("wx_msg_log")
public class WxMsgLog implements Serializable {

	private static final long serialVersionUID = 2892248514883451461L;
	@TableId(type = IdType.AUTO)
	private Integer id;
	private String msgType;
	private String fromUsername;
	private String event;
	private String eventKey;
	private String ticket;
	private String mediaId;
	private String content;
	private String locationX;
	private String locationY;
	private String label;

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")

	@TableField(fill = FieldFill.INSERT)
	private Date createTime;

	public WxMsgLog( Map<String, Object> allFieldsMap){
		String msgType1 = (String) allFieldsMap.get("MsgType");
		this.msgType=msgType1;

		this.fromUsername= (String) allFieldsMap.get("FromUserName");
		switch (msgType1){
			case "voice":
			case "image":
				this.mediaId= (String) allFieldsMap.get("MediaId");
				break;
			case "text":
				this.content= (String) allFieldsMap.get("Content");
				break;
			case "location":
				this.locationX= (String) allFieldsMap.get("Location_X");
				this.locationY= (String) allFieldsMap.get("Location_Y");
				this.label= (String) allFieldsMap.get("label");
				break;
			case "event":
				String event1 = (String) allFieldsMap.get("Event");
				this.event= event1;
				this.eventKey= (String) allFieldsMap.get("EventKey");
				if ("SCAN".equals(event1)) {
					this.ticket = (String) allFieldsMap.get("Ticket");
				}
				break;
			case "subscribe":
				String event = (String) allFieldsMap.get("Event");
				this.event=event;
				if("subscribe".equals(event)&!this.eventKey.equals("")){
					this.ticket = (String) allFieldsMap.get("Ticket");
				}
				break;

		}
	}
}
